<?php
class Wee_Logging_Adminhtml_LoggingController extends Mage_Adminhtml_Controller_Action{
    public function indexAction(){
        $this -> _title($this -> __('System')) -> _title($this -> __('Admin Actions Logs')) -> _title($this -> __('Report'));
        $this -> loadLayout();
        $this -> _setActiveMenu('system/wee_logging');
        $this -> renderLayout();
    }
    public function gridAction(){
        $this -> loadLayout();
        $this -> renderLayout();
    }
    public function detailsAction(){
        $this -> _title($this -> __('System')) -> _title($this -> __('Admin Actions Logs')) -> _title($this -> __('Report')) -> _title($this -> __('View Entry'));
        $eventId = $this -> getRequest() -> getParam('event_id');
        $model = Mage :: getModel('wee_logging/event') -> load($eventId);
        if (!$model -> getId()){
            $this -> _redirect('*/*/');
            return;
        }
        Mage :: register('current_event', $model);
        $this -> loadLayout();
        $this -> _setActiveMenu('system/wee_logging');
        $this -> renderLayout();
    }
    public function exportCsvAction(){
        $this -> _prepareDownloadResponse('log.csv', $this -> getLayout() -> createBlock('wee_logging/adminhtml_index_grid') -> getCsvFile());
    }
    public function exportXmlAction(){
        $this -> _prepareDownloadResponse('log.xml', $this -> getLayout() -> createBlock('wee_logging/adminhtml_index_grid') -> getExcelFile());
    }
    public function archiveAction(){
        $this -> _title($this -> __('System')) -> _title($this -> __('Admin Actions Logs')) -> _title($this -> __('Archive'));
        $this -> loadLayout();
        $this -> _setActiveMenu('system/wee_logging');
        $this -> renderLayout();
    }
    public function archiveGridAction(){
        $this -> loadLayout();
        $this -> renderLayout();
    }
    public function downloadAction(){
        $archive = Mage :: getModel('wee_logging/archive') -> loadByBaseName($this -> getRequest() -> getParam('basename'));
        if ($archive -> getFilename()){
            $this -> _prepareDownloadResponse($archive -> getBaseName(), $archive -> getContents(), $archive -> getMimeType());
        }
    }
    protected function _isAllowed(){
        switch ($this -> getRequest() -> getActionName()){
        case 'archive': case 'download': case 'archiveGrid': return Mage :: getSingleton('admin/session') -> isAllowed('admin/system/wee_logging/backups');
            break;
        case 'grid': case 'exportCsv': case 'exportXml': case 'details': case 'index': return Mage :: getSingleton('admin/session') -> isAllowed('admin/system/wee_logging/events');
            break;
        }
    }
}
